﻿using SuperX.Common.Object;
using System;
using System.Collections.Generic;
using System.Text;

namespace SuperX.Common.Collection
{
    // 
    public abstract class BasicItemsCollection : BasicObject, ICollectionNotify
    {
        public event EventHandler<CollectionChangedArgs> ItemAdded;
        public event EventHandler<CollectionChangedArgs> ItemCleared;
        public event EventHandler<CollectionChangedArgs> ItemRemoved;
        public event EventHandler<CollectionChangedArgs> ItemReplaced;

        /// <summary>
        /// Notifies the item cleared.
        /// </summary>
        public void NotifyItemCleared()
        {
            EventHandler<CollectionChangedArgs> itemCleared = this.ItemCleared;
            if (itemCleared == null)
            {
                return;
            }
            itemCleared(this, new CollectionChangedArgs(this));
        }

        /// <summary>
        /// Notifies the item removed.
        /// </summary>
        /// <param name="item">The item.</param>
        public void NotifyItemRemoved(object item)
        {
            EventHandler<CollectionChangedArgs> itemRemoved = this.ItemRemoved;
            if (itemRemoved == null)
            {
                return;
            }
            itemRemoved(this, new CollectionChangedArgs(item));
        }

        /// <summary>
        /// Notifies the item added.
        /// </summary>
        /// <param name="item">The item.</param> 
        public void NotifyItemAdded(object item)
        {
            EventHandler<CollectionChangedArgs> itemAdded = this.ItemAdded;
            if (itemAdded == null)
            {
                return;
            }
            itemAdded(this, new CollectionChangedArgs(item));
        }

        /// <summary>
        /// Notifies the item Replaced.
        /// </summary>
        /// <param name="item">The item.</param>
        public void NotifyItemReplaced(object item)
        {
            EventHandler<CollectionChangedArgs> itemReplaced = this.ItemReplaced;
            if (itemReplaced == null)
            {
                return;
            }
            itemReplaced(this, new CollectionChangedArgs(item));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="item"></param>
        public abstract void Add(object item);

        /// <summary>
        /// 
        /// </summary>
        public abstract void Clear();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="item"></param>
        public abstract void Remove(object item);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="item"></param>
        public abstract void Replace(object item);
    }
}
